<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>设备管理</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="../app/index.do"></a>
			</div>
			<div class="header-title">设备管理列表</div>
		</div>

	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="pro_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
			<div id="pro_tb" class="search-show">
				<div class="search-input">
				<span>项目：</span>
				<span><input style="width: 100%;" id="projectitemid" name="projectitemid" class="easyui-combobox"
						editable="false"
						data-options="
							    valueField: 'id',
							    textField: 'name',
							    url: '../projectitemlist.do?status=2',
							    onLoadSuccess : function(data){ 
								    if(data.length>0){
								    	$('#projectitemid').combobox('setValue',data[0].id);
							    	}
							    },onSelect: function(rec){
							    	projectitemid = rec.id;
							    	loadData()
							    },panelHeight: 'auto'"></span>
					
				</div>
				<div class="search-input text-right">
					<a href="javascript:void(0)" class="d-btn btn-blue" onclick="newpro()">添加</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	var currentPro;
	var projectitemid;
	function loadData() {
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			url : "../equipmentList",
			method : 'get',
			queryParams : {
				projectitemid : projectitemid
			},
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '项目名',
				width : '100%',
				formatter : function(value,row,index) {
					var html = '';
					html += '<div class="info-unreviewed">'
						if (row.item){
							html += '<div class="info-item-name" style="width:'+ ellipsis() +'px;margin-bottom:10px;">'+ row.item.name +'</div>'
						}	
					html += '<div class="info-item-content" style="width:'+ ellipsis2() +'px;">'+ row.name +'</div>'
					html += '<div class="info-num col-2"><span class="c-blue"><b>开机维保时长</b>'+ row.startinterval +'<span class="info-unit">小时</span></span><span class="c-green"><b>日常维保时长</b>'+ row.dailyinterval+'<span class="info-unit">天</span></span></div>';
					html += '<div class="edit"><span class="info-edit" onclick="updatepro('+index+')"></span><span class="info-delete" onclick="deletepro('+index+')"></span></div></div>';
					return html;
				}
			} ] ]
		});
	}
	function ellipsis(){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-60
		return width;
	}
	function ellipsis2(){
		var WIDTH = $("body").width();
		var width;
		width = WIDTH-10
		return width;
	}	
	function refreshProTable() {
		$('#pro_table').datagrid("load", {
			projectitemid : projectitemid
		});
	}
	function newpro() {
		window.location.href = "../app/equipmentadd.do";
	}
	function updatepro(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		window.location.href = "../app/equipmentadd.do?id=" + item.id;
	}
	function deletepro(index) {
		currentPro = $("#pro_table").datagrid('getRows')[index];
		if (currentPro){
			$.messager.confirm("操作提示", "您确定要执行操作吗？", function(data) {
				if (data){
					$.ajax({
						type : 'POST',
						url : "../equipmentDelete.do?id=" + currentPro.id,
						contentType : "application/json",
						success : function(data) {
							if (data.success){
								$.messager.show({
									title : '删除',
									msg : '删除成功',
									timeout : 5000,
									showType : 'slide'
								});
								refreshProTable();
							}else{
								$.messager.alert('删除', '删除失败', 'error');
							}
						},
						dataType : "json"
					});
				}else{
				}
			});
		}else{
			$.messager.alert('更新', '请选择要删除的设备', 'warning');
		}
	}
</script>
</html>